package com.esri.android.map;

import android.os.AsyncTask;
import android.util.Log;
import com.esri.android.map.event.OnStatusChangedListener;
import com.esri.android.map.event.OnWebMapLoadListener;
import com.esri.core.portal.BaseMap;
import com.esri.core.portal.PortalItem;
import com.esri.core.portal.WebMap;
import com.esri.core.portal.WebMapLayer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public class c extends AsyncTask<WebMap, Integer, List<Layer>> {
    private final OnWebMapLoadListener a;
    private final MapView b;
    private final a c;

    public c(MapView mapView, a aVar, OnWebMapLoadListener onWebMapLoadListener) {
        this.a = onWebMapLoadListener;
        this.b = mapView;
        this.c = aVar;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // android.os.AsyncTask
    /* renamed from: a */
    public List<Layer> doInBackground(WebMap... webMapArr) {
        WebMap webMap;
        ArrayList arrayList = new ArrayList();
        if (webMapArr == null) {
            webMap = null;
        } else {
            try {
                webMap = webMapArr[0];
            } catch (UnsupportedOperationException e) {
                this.b.a(OnStatusChangedListener.STATUS.fromInt(OnStatusChangedListener.EsriStatusException.INIT_FAILED_WEBMAP_UNSUPPORTED_LAYER));
                Log.e(com.esri.core.internal.a.a, "Unsupported WebMap content.", e);
            } catch (Throwable th) {
                this.b.a(th);
            }
        }
        if (webMap == null) {
            return arrayList;
        }
        PortalItem info = webMap.getInfo();
        b bVar = new b(webMap, this.b, info != null ? info.getPortal() : null, true, this.a);
        ArrayList arrayList2 = new ArrayList();
        a aVar = this.c;
        if (aVar != null && aVar.d()) {
            arrayList.addAll(this.c.b());
            for (Layer layer : this.c.b()) {
                layer.a(true);
            }
        } else {
            a aVar2 = this.c;
            BaseMap a2 = aVar2 != null ? aVar2.a() : null;
            if (a2 == null) {
                a2 = webMap.getBaseMap();
            }
            if (a2 != null && a2.getBaseMapLayers() != null && !a2.getBaseMapLayers().isEmpty()) {
                ArrayList arrayList3 = new ArrayList();
                for (WebMapLayer webMapLayer : a2.getBaseMapLayers()) {
                    if (webMapLayer.isReference()) {
                        arrayList2.add(webMapLayer);
                    } else {
                        arrayList3.add(webMapLayer);
                    }
                }
                List<Layer> a3 = bVar.a(arrayList3);
                arrayList.addAll(a3);
                for (Layer layer2 : a3) {
                    layer2.a(true);
                }
            }
        }
        arrayList.addAll(bVar.a(webMap.getOperationalLayers()));
        a aVar3 = this.c;
        if (aVar3 != null && aVar3.d()) {
            arrayList.addAll(this.c.c());
            for (Layer layer3 : this.c.c()) {
                layer3.a(true);
            }
        } else {
            List<Layer> a4 = bVar.a(arrayList2);
            arrayList.addAll(a4);
            for (Layer layer4 : a4) {
                layer4.a(true);
            }
        }
        return arrayList;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // android.os.AsyncTask
    /* renamed from: a */
    public void onPostExecute(List<Layer> list) {
        super.onPostExecute(list);
        if (this.b == null) {
            return;
        }
        for (Layer layer : list) {
            if (layer != null) {
                this.b.addLayer(layer);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static class a {
        private final BaseMap a;
        private final List<Layer> b;
        private final List<Layer> c;

        public a(BaseMap baseMap) {
            this.a = baseMap;
            this.b = Collections.EMPTY_LIST;
            this.c = Collections.EMPTY_LIST;
        }

        public a(List<Layer> list, List<Layer> list2) {
            this.a = null;
            this.b = list == null ? Collections.EMPTY_LIST : list;
            this.c = list2 == null ? Collections.EMPTY_LIST : list2;
        }

        public BaseMap a() {
            return this.a;
        }

        public List<Layer> b() {
            return this.b;
        }

        public List<Layer> c() {
            return this.c;
        }

        public boolean d() {
            return (this.b.isEmpty() && this.c.isEmpty()) ? false : true;
        }
    }
}
